option(ENABLE_PCMSOLVER "Enable PCMSolver library" OFF)

# Check for non-PCMSolver friendly compilers
if(CMAKE_CXX_COMPILER MATCHES Cray OR CMAKE_CXX_COMPILER MATCHES NVHPC OR CMAKE_CXX_COMPILER MATCHES XL)
    set(ENABLE_PCMSOLVER OFF)
    message(STATUS "PCMSolver DISABLED: not supported by the ${CMAKE_CXX_COMPILER} compiler")
endif()

if(ENABLE_PCMSOLVER)
  # User signal to try pre-built PCMSolver
  if(PCMSOLVER_ROOT)
    find_package(PCMSolver)
  endif()
  # Build PCMSolver as external package if pre-built failed or not signaled
  if(NOT PCMSolver_FOUND)
    message(STATUS "PCMSolver not found. The pre-packaged version will be built.")
    find_package(ZLIB QUIET)
    if(NOT ZLIB_FOUND)
      set(ENABLE_PCMSOLVER OFF)
      message(STATUS "Polarizable Continuum Model via PCMSolver DISABLED")
      message(STATUS " PCMSolver dependencies NOT satisfied:")
      if(NOT ZLIB_FOUND)
        IF (ENABLE_STATIC_LINKING)
          message(STATUS "  - install static Zlib development libraries")
        else()
          message(STATUS "  - install dynamic Zlib development libraries")
        endif()
      endif()
    else()
      add_definitions(-DHAS_PCMSOLVER)
      message(STATUS "Polarizable Continuum Model via PCMSolver ENABLED")
      add_subdirectory(DALTON/pcm)
    endif()
  endif()
else()
  message(STATUS "Polarizable Continuum Model via PCMSolver DISABLED")
endif()
